package com.tencent.txcc.service.impl;

import com.tencent.txcc.service.ICommonService;
import com.tencent.txcc.utils.StrUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
public class CommonServiceImpl implements ICommonService {

    @Autowired
    private RedisTemplate<Object, Object> redisTemplate;

    private String redisOrderToken = "orderToken:%s:%s";

    @Override
    public String createToken(Long courseIds) {
        String token = StrUtils.getRandomString(8);
        Long loginId = 42L;
        String redisKey = String.format(redisOrderToken, loginId, courseIds);
        redisTemplate.opsForValue().set(redisKey, token, 3000000, TimeUnit.MILLISECONDS);
        return token;
    }
}
